package com.ems.service.impl;

import com.ems.entity.BatteryStatisticsDayEntity;
import com.ems.mapper.BatteryStatisticsDayMapper;
import com.ems.service.IBatteryStatisticsDayService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ems.util.SnowflakeIdWorker;
import com.ems.util.StateEnum;
import com.ems.util.StateException;
import com.ems.vo.BatteryStatisticsDayVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * BMS数据备份表，每日凌晨备份前一天数据 服务实现类
 * </p>
 *
 * @author WuZH
 * @since 2024-05-07
 */
@Service
public class BatteryStatisticsDayServiceImpl extends ServiceImpl<BatteryStatisticsDayMapper, BatteryStatisticsDayEntity> implements IBatteryStatisticsDayService {

    @Resource
    private BatteryStatisticsDayMapper batteryStatisticsDayMapper;

    @Override
    public List<BatteryStatisticsDayVo> queryList ( BatteryStatisticsDayVo batteryStatisticsDayVo ) {
        List<BatteryStatisticsDayVo> batteryStatisticsDayVos = batteryStatisticsDayMapper.queryList ( batteryStatisticsDayVo );
        return batteryStatisticsDayVos;
    }

    @Override
    public BatteryStatisticsDayVo saveSingle ( BatteryStatisticsDayVo batteryStatisticsDayVo ) {
        if ( batteryStatisticsDayVo == null ) {
            throw new StateException ( StateEnum.REQUEST_PARAM_EXCE );
        }
        BatteryStatisticsDayEntity batteryStatisticsDayEntity = new BatteryStatisticsDayEntity ();
        BeanUtils.copyProperties ( batteryStatisticsDayVo, batteryStatisticsDayEntity );
        batteryStatisticsDayEntity.setId ( SnowflakeIdWorker.getInstance ().nextStringId () );
        batteryStatisticsDayEntity.setCreateTime ( new Date () );
        int insert = baseMapper.insert ( batteryStatisticsDayEntity );
        if ( insert == 0 ) {
            throw new StateException ( StateEnum.INSERT_EXCE );
        }
        return batteryStatisticsDayVo;
    }

}
